
import Taro from '@tarojs/taro';
import { View, Text, Image } from "@tarojs/components";
import PropTypes from 'prop-types';
import AutoFormId from "@/components/autoFormId/index";
import './index.scss'

class DrugItem extends Taro.Component {
    static defaultProps = {
        drugItem: {},
        renderSolt: '',
        isDetails: false,
        isuse: false,
        itemTap: () => { },
        isnear: false
    };
    constructor(props) {
        super(props);
        this.state = {}
    }
    render() {
        let { isDetails, isuse, itemTap, isnear, drugItem } = this.props;
        let pic = '';
        if (drugItem.status != 0 ){
            if (drugItem.status == 3) {
                pic = require('../../assets/imgs/notedhs/img_note_dhs.png')
            }else {
                if (drugItem.isJxq === '已过期'){
                    pic = require('../../assets/imgs/drug/ypgl_img_note_ygq.png');
                } else if (drugItem.isJxq === '将过期') {
                    pic = require('../../assets/imgs/drug/ypgl_img_note_jgq.png');
                }else {
                    pic = '' 
                }
            }
        }
        return (
            // {/* 状态：在用 */ }
            <View onClick={(e) => { itemTap(e, drugItem) }} className={`drugItem pl-3-5 pt-3-5 pr-4  ft26 bg_fff vo_h mb-2-5 bdr_10 ${isDetails ? 'pb-2-5' : 'pb-5'}`}>
                <AutoFormId renderCat={
                    <View className='text-l ft26'>
                        {isnear ? null : <View className='fc_000 mb-4-5 flex flex-r flex-item-between'><Text>有效期：{drugItem.validitydate}</Text> {isuse ? <Text className='fc_960'></Text> : null} </View>}
                        <View className='fc_53C mb-2 flex flex-r flex-item-between ft_w600'>
                            <Text className={isnear ? 'ft26' : 'ft32'}>药品名：{drugItem.drugname}</Text>
                            {isnear ? <Image className='ml-0-5' style={{ width: Taro.pxTransform(12), height: Taro.pxTransform(22), opacity: 0.6 }} src={require('../../assets/imgs/home/home_icon_pressed.png')} /> : null}
                        </View>
                        <View className='pr-5-6 mb-2'>
                            <Text>数量：{drugItem.quantity - drugItem.usernum}支/<Text className='ft20'>{drugItem.quantity}支</Text></Text>
                            <Text className='pl-9'>规格：{drugItem.standard}</Text>
                        </View>
                        <View className={`pb-3 ${isnear ? 'line-b' : ''}`}> 批号：{drugItem.batch}</View>
                        {isnear ? <View className='fc_000 mb-2 pt-3 flex flex-r flex-item-between'><Text>有效期：{drugItem.validitydate}</Text></View> : null}
                        <View className={`fc_65C ${isnear ? 'mb-0' : 'pt-3 mb-2'}`} >存放：{drugItem.wardname || drugItem.ward}</View>
                        {isnear ? null : <View><View className='mb-4-5 fc_65C'>所属科室：{drugItem.departmentname || drugItem.department}</View> <View className='fc_FF8'>{drugItem.xjr ? '巡检人':'领取人'}：{drugItem.lqr || drugItem.userget  || drugItem.xm || drugItem.xjr}</View></View>}
                    </View>
                }
                ></AutoFormId>
                {drugItem.status != 0 && <Image className='drugItem-img' style={{ top: `${isDetails ? Taro.pxTransform(162) : (isnear ? Taro.pxTransform(45) : Taro.pxTransform(100))}` }} src={pic}></Image>}
                {this.props.renderSolt}
            </View>
        );
    }
}

export default DrugItem;

DrugItem.propTypes = {
    drugItem: PropTypes.object,
    renderSolt: PropTypes.string,
    isDetails: PropTypes.bool,
    isuse: PropTypes.bool,
    isnear: PropTypes.bool
}